class MyHashMap {
    private class Node{
        int key;
        int value;
        Node next;
        public Node(int key, int value, Node next) {
            this.key = key;
            this.value = value;
            this.next = next;
        }
    }
    private int size;
    private static final int DEFAULT_CAPACITY = 769;
    private static final double LOAD_FACTOR = 0.75;
    private int M;
    private Node[] data;

    public MyHashMap() {
        this(DEFAULT_CAPACITY);
    }
    public MyHashMap(int initCap) {
        this.data = new Node[initCap];
        this.M = initCap;
    }
    
    public void put(int key, int value) {
        int index = hash(key);
        for(Node cur = data[index]; cur != null; cur = cur.next){
            if(cur.key == key){
                cur.value = value;
                return;
            }
        }
        Node node = new Node(key, value, data[index]);
        data[index] = node;
        size++;
    }
    
    public int get(int key) {
        int index = hash(key);
        for(Node cur = data[index]; cur != null; cur = cur.next){
            if(cur.key == key){
                return cur.value;
            }
        }
        return -1;
    }
    
    public void remove(int key) {
        int index = hash(key);
        Node head = data[index];
        if(head == null){
            return;
        }
        if(head.key == key){
            data[index] = head.next;
            head.next = head = null;
            size--;
        }
        Node prev = head;
        while(prev != null){
            if(prev.next != null && prev.next.key == key){
                Node cur = prev.next;
                prev.next = cur.next;
                cur.next = cur = null;
                size--;
            }
            prev = prev.next;
        }
        
    }

    public int hash(int key){
        return key % M;
    }
}

/**
 * Your MyHashMap object will be instantiated and called as such:
 * MyHashMap obj = new MyHashMap();
 * obj.put(key,value);
 * int param_2 = obj.get(key);
 * obj.remove(key);
 */